﻿using UnityEngine;

namespace Framework
{
    public class WorldGenerator
    {
        static float scale = 0.02f;
        public static Chunk CreatChunk(Vector3Int cnk)
        {
            Chunk chunk = new Chunk();
            chunk.position = cnk;
            Vector3 chunkOffset = CoordConvert.Cnk2Pos(cnk);
            for (int x = 0; x < Chunk.size.x+1; x++)
            {
                for (int z = 0; z < Chunk.size.z+1; z++)
                {
                    //tip:must input float
                    float heightLevel = Mathf.PerlinNoise((x + chunkOffset.x) * scale, (z + chunkOffset.z) * scale) * Chunk.size.y;
                    for (int y = 0; y < Chunk.size.y; y++)
                    {
                        chunk.blocks[x, y, z] = heightLevel < y ? BlockType.Empty : BlockType.Dirt;
                    }
                }
            }
            return chunk;
        }
    }


}
